﻿using AutoMapper;
using BS.Infra;
using BS.Infra.Interface;
using BS.Write.Api.Handler.Breeding;
using MediatR;

namespace BS.Read.Api.Handler.Breeding
{
    public class GetBreedingListHandler : IRequestHandler<GetBreedsingRequestDTO, ApiResult>
    {
        private readonly IBreedingsRepository _breedingsRepository;

        private readonly ILogger<GetBreedingListHandler> _logger;

        private readonly IMapper _mapper;

        public GetBreedingListHandler(IBreedingsRepository breedingsRepository,
            ILogger<GetBreedingListHandler> logger,
            IMapper mapper)
        {
            _breedingsRepository = breedingsRepository;
            _logger = logger;
            _mapper = mapper;
        }
        public async Task<ApiResult> Handle(GetBreedsingRequestDTO request, CancellationToken cancellationToken)
        {
            try
            {

                var response = await _breedingsRepository.GetAllAsync(x=>x.IsDeleted==false);
                return ApiResult.Ok(data:response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error in GetBreedingListHandler");
                return  ApiResult.Fail(ex.Message);
            }
        }
    }
}
public class GetBreedsingRequestDTO:IRequest<ApiResult>
{

}
public class GetBreedsingReponseDTO
{
    public int BreedingId { get; set; }
    /// <summary>
    /// 品种
    /// </summary>
    public string Breed { get; set; } = string.Empty;
    /// <summary>
    /// 来源
    /// </summary>
    public string Source { get; set; } = string.Empty;
    /// <summary>
    /// 饲养天数
    /// </summary>
    public int FeedingDays { get; set; }
    /// <summary>
    /// 饲料品牌
    /// </summary>
    public string BreedingBrand { get; set; } = string.Empty;
    /// <summary>
    /// 饲养负责人
    /// </summary>
    public string HeadFeeder { get; set; } = string.Empty;
    /// <summary>
    /// 出栏日期
    /// </summary>
    public DateTime PublicationDate { get; set; } = DateTime.Now;
    /// <summary>
    /// 硕源ID
    /// </summary>
    public int TrId { get; set; }
}